const fs = require('fs');
const path = require('path');
const multer = require('multer');
const express = require('express');
const cors = require("cors");


const app = express();
const upload = multer({ dest: "./img" });//设置保存的位置

app.use(cors());
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

app.post('/getPic', upload.single('pic'), (req, res) => {
    let file = req.file;
    console.log(file);
    let extname = path.extname(file.originalname);
    let fielpath = file.path;
    let filename = file.filename + extname;
    fs.rename(fielpath, path.join(path.dirname(fielpath), filename), (err) => {
        if (err) throw err;
    });
    console.log(filename);
    console.log(req.file);
});


app.listen(3065, () => {
    console.log(`http://localhost:3065`);
});
